package com.woniuxy.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.system.entity.DataRecord;
import com.woniuxy.system.entity.PerformanceDepartment;
import com.woniuxy.system.mapper.DataRecordMapper;
import com.woniuxy.system.mapper.PerformanceDepartmentMapper;
import com.woniuxy.system.service.PerformanceDepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 部门管理 服务实现类
 * </p>
 *
 * @author woniuxy
 * @since 2022-06-01
 */
@Service
public class PerformanceDepartmentServiceImpl extends ServiceImpl<PerformanceDepartmentMapper, PerformanceDepartment> implements PerformanceDepartmentService {

    @Autowired
    DataRecordMapper dataRecordMapper;
    @Autowired
    PerformanceDepartmentMapper performanceDepartmentMapper;
    @Override
    public boolean addPerformanceDepartment(PerformanceDepartment performanceDepartment) {
        DataRecord dataRecord = new DataRecord();
        dataRecord.setCreateTime(new Date());
        dataRecord.setInfo("新建部门管理");
        int insert = dataRecordMapper.insert(dataRecord);
        System.out.println("datarecordeId="+dataRecord.getId());
        performanceDepartment.setRecordId(dataRecord.getId());
        int insert1=performanceDepartmentMapper.insert(performanceDepartment);
        if(insert==1&&insert1==1){
            return  true;
        }
        return false;
    }

    @Override
    public Page<PerformanceDepartment> getAllPerformanceDepartment(IPage<PerformanceDepartment> page, Wrapper<PerformanceDepartment> wrapper) {
        return performanceDepartmentMapper.getAllPerformanceDepartment(page,wrapper);
    }

    @Override
    public Integer findUserByDId(Long id) {
        return performanceDepartmentMapper.findUserByDId(id);
    }
}
